package Controller;

import Util.JDBCUtill;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import pojo.user;

import java.util.List;

public class UserController {
    @FXML
    private TableView<user> userTable;
    @FXML
    private TableColumn<user, String> passwordFile;

    @FXML
    private Button teacherbut;

    @FXML
    private TableColumn<user, String>  isadminFile;

    @FXML
    private TableColumn<user, String>  IDFile;

    @FXML
    private Button addbut;

    @FXML
    private Button deletebut;

    @FXML
    private TableColumn<user, String>  userCountFile;

    @FXML
    private Button classbut;

    @FXML
    private Button userbut;

    @FXML
    private Button changebut;
    @FXML
    void initialize() {
        System.out.println(Main.SharedData.isAdmin);
        if(Main.SharedData.isAdmin==1) {
            teacherbut.setVisible(true);
            userbut.setVisible(true);
            addbut.setVisible(true);
            changebut.setVisible(true);
            deletebut.setVisible(true);
        }
        getDates();
    }
    private void getDates() {
        List<user> users = JDBCUtill.readUserlDate();
        IDFile.setCellValueFactory(new PropertyValueFactory<>("id"));
        passwordFile.setCellValueFactory(new PropertyValueFactory<>("password"));
        isadminFile.setCellValueFactory(new PropertyValueFactory<>("isadmin"));
        userCountFile.setCellValueFactory(new PropertyValueFactory<>("userCount"));
        userTable.setItems(FXCollections.observableArrayList(users));
    }
    @FXML
    public void ClassInternationControl(ActionEvent event) {
        Main.changeView("ClassRoom.fxml");
    }
    @FXML
    void TeacherInternationControl(ActionEvent event) {
        Main.changeView("teacher-view.fxml");
    }


    @FXML
    void UserInternationControl(ActionEvent event) {
        initialize();
    }

}
